package cn.uexpo.lhz.core.error;

import cn.uexpo.lhz.base.BaseApiService;
import cn.uexpo.lhz.base.BaseResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;

import static cn.uexpo.lhz.dd.RobotHelperUtil.sdkDemoJava;


/**
 * @Author 小坏
 * @Date 2020/6/18 15:39
 * @Version 1.0
 * @program: 父工程 manage 万物起源之地
 * @description: 全局捕获异常
 */
//@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends BaseApiService<JSONObject> {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public BaseResponse<JSONObject> exceptionHandler(Exception e) {

        log.info("###>>>>lan全局捕获异常一下信息<<<<<<<<###,error:{}",e.toString());
        StackTraceElement stackTraceElement = e.getStackTrace()[0];
        String errorMsg = ">>>>>>>文件名："+stackTraceElement.getFileName()+
                "\r\n类名："+stackTraceElement.getClassName()+
                "\r\n方法名："+stackTraceElement.getMethodName()+
                "\r\n抛出异常行号："+stackTraceElement.getLineNumber()+
                "\r\n机构ID异常，无法获取本机构信息："+e.toString();
       // System.out.println(errorMsg);
       sdkDemoJava(errorMsg);
        return setResultError("系统错误!"+ errorMsg);
    }
}
